package com.ddzj.scaffold.service.impl;

import com.ddzj.scaffold.entity.User;
import com.ddzj.scaffold.service.UserService;
import com.ddzj.scaffold.vo.SecurityUserDetailsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * @Author:yangzibo
 * @CreateTime:2024-04-14 13:45
 * @Description:
 * @Version:1.0
 **/
@Service
public class SercurityUSerDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private UserService userService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        User user = userService.findByAccount(username);
        SecurityUserDetailsVo vo = new SecurityUserDetailsVo();
        vo.setId(user.getId());
        vo.setUsername(user.getAccount());
        vo.setPassword(user.getPwd());
        return vo;
    }
}
